package com.dmooo.ymx.adapter;

import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.dmooo.ymx.R;
import com.dmooo.ymx.bean.JinFenBean;
import com.dmooo.ymx.common.SPUtils;

import java.text.DecimalFormat;
import java.util.List;

public class JinFenAdapter extends BaseQuickAdapter<JinFenBean.Item,BaseViewHolder> {
    DecimalFormat df = new DecimalFormat("0.00");
    public JinFenAdapter(int layoutResId, @Nullable List<JinFenBean.Item> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder holder, JinFenBean.Item item) {
        ImageView imageView = holder.getView(R.id.image);
        Glide.with(mContext).load(item.imageInfo.imageList.get(0).url).placeholder(R.drawable.no_banner).dontAnimate().into(imageView);
        ((TextView) holder.getView(R.id.title_child)).setText(item.skuName);
        //券后2
        TextView tx2_2 = holder.getView(R.id.tx2_2);
        //设置删除线
        tx2_2.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        tx2_2.setText("原价:￥" + item.priceInfo.price);
        //内部
        TextView tx3 = holder.getView(R.id.tx3);
        if(item.couponInfo==null||item.couponInfo.couponList.size()<=0){
            tx3.setText(0 + "");
        }else{
            tx3.setText(item.couponInfo.couponList.get(0).discount + "");
        }
        TextView tx2 = holder.getView(R.id.tx2);
        try {
            tx2.setText("￥" + df.format(Double.valueOf(item.priceInfo.price) -Double.valueOf(item.couponInfo.couponList.get(0).discount)));
        } catch (Exception e) {
            tx2.setText("￥" + item.priceInfo.price);
        }
            holder.setText(R.id.tx4, "奖:" + df.format(Double.valueOf(tx2.getText().toString().replace("￥",""))* Double.valueOf(df.format(Double.valueOf(item.commissionInfo.commissionShare)/100))*Double.parseDouble(df.format((float) SPUtils.getIntData(mContext, "rate", 0) / 100))));
        if (Double.valueOf(item.inOrderCount30Days) < 1000) {
            holder.setText(R.id.tx5, "销量:" + Double.valueOf(item.inOrderCount30Days));
        } else {
            holder.setText(R.id.tx5, "销量:" + df.format(Double.valueOf(item.inOrderCount30Days) / 10000) + "万");
        }
    }
}
